<%@ page import="com.ld.businessCard.entity.Card" %>
<%@ page import="java.util.List" %>
<%@ page import="com.ld.businessCard.service.impl.CardServiceImpl" %>
<%@ page import="com.ld.businessCard.service.CardService" %>
<%@ page import="com.ld.businessCard.entity.User" %>
<%--  Created by IntelliJ IDEA.--%>
<%--  User: 刘邓--%>
<%--  Date: 2023-06-10--%>
<%--  Time: 16:13--%>
<%--  To change this template use File | Settings | File Templates.--%>
<%--&ndash;%&gt;--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>我的回收站</title>
    <style>
        td {
            color: #ff4b2b;
            text-align: center;
        }
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        a {
            text-decoration: none;
            color: black;
        }
        a:hover {
            color: blue;
        }
        .container {
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35), 0 10px 10px rgba(0, 0, 0, 0.22);
            position: relative;
            overflow: hidden;
            width: 80%;
            max-width: 100%;
            min-height: 480px;
            margin:0 auto;
        }
    </style>
</head>
<body>
<%!
    private CardService cardService= new CardServiceImpl();
%>
<%
    User user = (User)(session.getAttribute("user"));
	String homePath;
	if(user.getStatus() == 0){
		homePath = "user";
    }else {
		homePath = "admin";
    }
    out.println("<a href='/home/"+homePath + "/index.jsp'" + "  style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:blue'>返回个人管理页面</a><br>");
    List<Card> cards = cardService.getRecycleCardsByUserId(user.getId());
    if (cards.isEmpty()) out.println("<h1 style='width: 80%;height:400px;margin: 0 auto;text-align:center;line-height:400px'>暂无更多信息!<h1>");
    else {
        out.println("<table class='container'>" +
                "<tr>" +
                "<th>姓名</th>" +
                "<th>性别</th>" +
                "<th>邮箱</th>" +
                "<th>操作</th>" +
                "</tr>");
        if (!cards.isEmpty())
            for (Card card : cards) {
				String sex0 = card.getSex() == 0?"男":"女";
                String recoverDOM = "<td><a class='recover' href=" + "'/card/recover?id=" + card.getId() + "'>恢复" + "</a></td>";
                String deletedDOM = "<td><a class='deleted' href=" + "'/card/delete?id=" + card.getId() + "'>彻底删除" + "</a></td>";
                out.println("<tr>");
                out.println("<td>" + card.getName() + "</td>");
                out.println("<td>" + sex0 + "</td>");
                out.println("<td>" + card.getEmail()+ "</td>");
                out.println(recoverDOM);
                out.println(deletedDOM);
                out.println("</tr>");
            }
        out.println("</table>");
    }
%>
</body>
<script>
    let deleted = document.getElementsByClassName("deleted");
    for (let i = 0; i < deleted.length; i++) {
        deleted[i].addEventListener("click",(e) => {
            let b = confirm("你确定要彻底删除吗?");
            if(b == false){
                e.preventDefault();
            }
        })
    }
    let recover = document.getElementsByClassName("recover");
    for (let i = 0; i < recover.length; i++) {
        recover[i].addEventListener("click",(e) => {
            let b = confirm("你确定要恢复吗?");
            if(b == false){
                e.preventDefault();
            }
        })
    }
</script>
</html>
